<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">
      <el-form-item label="园区名称:" prop="gardenName">
        <el-input v-model="queryData.gardenName" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('name')"/>
      </el-form-item>
      <el-form-item label="园区类型:" prop="gardenType">
        <el-select v-model="queryData.gardenType" placeholder="请选择" clearable @clear="formClear('gardenType')"
                   style="width: 200px">
          <el-option label="园区" value="1"/>
          <el-option label="写字楼" value="2"/>
        </el-select>
      </el-form-item>
      <el-form-item label="省市区:" prop="provinces">
        <el-cascader v-model="queryData.provinces" ref="cascader" :props="props" @change="handleChange" clearable
                     @clear="formClear('provinces')"/>
      </el-form-item>
      <el-form-item label="详细地址:" prop="address">
        <el-input v-model="queryData.address" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('address')"/>
      </el-form-item>
      <el-form-item label="上架状态:" prop="shelfStatus">
        <el-select v-model="queryData.shelfStatus" placeholder="请选择" clearable @clear="formClear('shelfStatus')"
                   style="width: 200px">
          <el-option label="未上架" value="0"/>
          <el-option label="上架" value="1"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
        <el-button type="primary" @click="$router.push('/parkManage/parkAdd')">新 增</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column type="index" label="序号" align="center"/>
      <el-table-column prop="gardenName" label="园区名称" align="center" show-overflow-tooltip/>
      <el-table-column prop="gardenType" label="园区类型" align="center" :formatter="(row) => row.gardenType == '1' ? '园区' : '写字楼'"/>
      <el-table-column prop="cardId" label="地址" align="center" show-overflow-tooltip
                       :formatter="(row) => `${row.province} - ${row.city} - ${row.county}`"/>
      <el-table-column prop="address" label="详情地址" align="center" show-overflow-tooltip/>
      <el-table-column prop="manageCompany" label="管理物业公司名称" align="center" width="150" show-overflow-tooltip/>
      <el-table-column prop="manageName" label="管理物业公司联系人" align="center" width="150"/>
      <el-table-column prop="phone" label="物业联系方式" align="center"/>
      <el-table-column prop="gardenSignString" label="添加方式" align="center"/>
      <el-table-column prop="checkStatusString" label="审核状态" align="center"/>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="{row}">
          <router-link :to="`/parkManage/parkAdd?id=${row.id}&audit=1`" class="el-link--primary">查 看</router-link>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import {getProvinces} from '@/utils/common.js'
  export default {
    computed: {
      ...mapGetters(['confirm']),
    },
    name: 'gardenHomeAudit',
    data() {
      return {
        delivery: false,
        authenticationArr: ['未认证', '自动认证'],
        typeArr: ['园区招商部', '开发商', '一房东', '二房东', '企业'],
        tableList: [],
        queryData: {
          provinces: null, // 省市区
          province: null, // 省
          city: null, // 市
          county: null, // 区
          address: null, // 地址
          gardenName: null, // 园区名字
          gardenType: null, // 园区类型：1园区；2写字楼
          shelfStatus: null, // 上架状态：0未上架；1上架
          pageNum: 1,
          pageSize: 10,
          total: 0
        },
        props: getProvinces(),
        formData: {},
        entity: null,
        drawer: false
      }
    },

    beforeMount() {
      this.getRequest()
    },
    methods: {
      handleChange(row) {
        const entity = this.$refs.cascader.getCheckedNodes()[0]
        const list = entity && entity.pathLabels && entity.pathLabels.length > 0 ? entity.pathLabels : [null, null, null]
        let arr = ['province', 'city', 'county']
        for (let i = 0; i < list.length; i++) this.queryData[arr[i]] = list[i]
      },
      /**
       *  推荐事件
       */
      async recommendEvent(row) {
        this.$confirm('确认修改该条数据吗?', '提示', this.confirm.options).then(async() => {
          await this.$ajax.post('/garden/update', { id: row.id, recommend: row.recommend === 1 ? 0 : 1 })
          this.$message.success('操作成功')
          this.getRequest()
        })
      },
      /**
       *  上架下架事件
       */
      async putawayEvent(row) {
        this.$confirm('确认修改该条数据吗?', '提示', this.confirm.options).then(async() => {
          await this.$ajax.post('/garden/update', { id: row.id, shelfStatus: row.shelfStatus === 1 ? 0 : 1 })
          this.$message.success('操作成功')
          this.getRequest()
        })
      },
      /**
       * 重置事件
       */
      onReset() {
        this.queryData.pageNum = 1
        this.queryData.province = null
        this.queryData.city = null
        this.queryData.county = null
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        this.queryData.pageNum = 1
        this.getRequest()
      },
      /**
       * 列表请求事件
       */
      async getRequest() {
        const formData = JSON.parse(JSON.stringify(this.queryData))
        delete formData.provinces
        const res = await this.$ajax.get('/garden/backstage/amendList', { params: formData })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * 新增 或 修改事件
       * row null 新增
       */
      entityInfoEvent(row) {
        this.entity = row, this.drawer = true
      },
      /**
       * 删除事件
       */
      deleteEvent(row) {
        this.$confirm(this.confirm.text, '提示', this.confirm.options).then(async() => {
          await this.$ajax.get(`/wx/rotation/id?id=${row.id}`)
          this.$message.success('操作成功')
          this.getRequest()
        })
      },
      /**
       * form置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      },
      /**
       * 取消抽屉事件
       */
      drawerClose() {
        this.drawer = false
      }
    }
  }
</script>

<style scoped>

</style>
